/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.route.system.entity;

import java.io.Serializable;
import java.util.List;
import javax.persistence.*;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author neco
 */
@Entity
@Table(name = "rps_route_description",  schema = "public")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "RpsRouteDescription.findAll", query = "SELECT r FROM RpsRouteDescription r"),
    @NamedQuery(name = "RpsRouteDescription.findByDescriptionId", query = "SELECT r FROM RpsRouteDescription r WHERE r.descriptionId = :descriptionId"),
    @NamedQuery(name = "RpsRouteDescription.findByDescriptionVehicleName", query = "SELECT r FROM RpsRouteDescription r WHERE r.descriptionVehicleName = :descriptionVehicleName"),
    @NamedQuery(name = "RpsRouteDescription.findByDescriptionIsPassing", query = "SELECT r FROM RpsRouteDescription r WHERE r.descriptionIsPassing = :descriptionIsPassing"),
    @NamedQuery(name = "RpsRouteDescription.findByDescriptionIsFareChanging", query = "SELECT r FROM RpsRouteDescription r WHERE r.descriptionIsFareChanging = :descriptionIsFareChanging"),
    @NamedQuery(name = "RpsRouteDescription.findByCompleteValue", query = "SELECT r FROM RpsRouteDescription r WHERE r.descriptionDirectionType.typeId = 1 AND (UPPER(r.descriptionVehicleName)  LIKE :descriptionVehicleName OR UPPER(r.descriptionStartStation.stationName) LIKE :stationName)"),
    @NamedQuery(name = "RpsRouteDescription.findByDescriptionVehicleNameEnd", query = "SELECT r FROM RpsRouteDescription r WHERE r.descriptionDirectionType.typeId = 2 AND  r.descriptionVehicleName = :descriptionVehicleName"),
    @NamedQuery(name = "RpsRouteDescription.findByDescriptionVehicleSpeed", query = "SELECT r FROM RpsRouteDescription r WHERE r.descriptionVehicleSpeed = :descriptionVehicleSpeed")})
public class RpsRouteDescription implements Serializable {
    
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "description_id", nullable = false)
    private Integer descriptionId;
    @Size(max = 200)
    @Column(name = "description_vehicle_name", length = 200)
    private String descriptionVehicleName;
    @Basic(optional = false)
    @Column(name = "description_is_passing", nullable = false)
    private boolean descriptionIsPassing;
    @Basic(optional = false)
    @Column(name = "description_is_fare_changing", nullable = false)
    private boolean descriptionIsFareChanging;
    @Basic(optional = false)
    @Column(name = "description_vehicle_speed", nullable = false)
    private double descriptionVehicleSpeed;
    @OneToMany(mappedBy = "scheduleRouteDescription")
    private List<RpsRouteTimeSchedule> rpsRouteTimeScheduleList;
    @OneToMany(mappedBy = "stationsRouteDescription")
    private List<RpsRouteStations> rpsRouteStationsList;
    @JoinColumn(name = "description_vehicle_type", referencedColumnName = "type_id")
    @ManyToOne
    private RpsVehicleType descriptionVehicleType;
    @JoinColumn(name = "description_fare_changing_station", referencedColumnName = "station_id")
    @ManyToOne
    private RpsStation descriptionFareChangingStation;
    @JoinColumn(name = "description_direction_type", referencedColumnName = "type_id")
    @ManyToOne
    private RpsDirectionType descriptionDirectionType;
    @OneToMany(mappedBy = "detailRouteDescription")
    private List<RpsRoutePaymentDetail> rpsRoutePaymentDetailList;
    
    @JoinColumn(name = "description_end_station", referencedColumnName = "station_id")
    @ManyToOne
    private RpsStation descriptionEndStation;
    @JoinColumn(name = "description_start_station", referencedColumnName = "station_id")
    @ManyToOne
    private RpsStation descriptionStartStation;

    public RpsRouteDescription() {
    }

    public RpsRouteDescription(Integer descriptionId) {
        this.descriptionId = descriptionId;
    }

    public RpsRouteDescription(Integer descriptionId, boolean descriptionIsPassing, boolean descriptionIsFareChanging, double descriptionVehicleSpeed) {
        this.descriptionId = descriptionId;
        this.descriptionIsPassing = descriptionIsPassing;
        this.descriptionIsFareChanging = descriptionIsFareChanging;
        this.descriptionVehicleSpeed = descriptionVehicleSpeed;
    }

    public Integer getDescriptionId() {
        return descriptionId;
    }

    public void setDescriptionId(Integer descriptionId) {
        this.descriptionId = descriptionId;
    }

    public String getDescriptionVehicleName() {
        return descriptionVehicleName;
    }

    public void setDescriptionVehicleName(String descriptionVehicleName) {
        this.descriptionVehicleName = descriptionVehicleName;
    }

    public boolean getDescriptionIsPassing() {
        return descriptionIsPassing;
    }

    public void setDescriptionIsPassing(boolean descriptionIsPassing) {
        this.descriptionIsPassing = descriptionIsPassing;
    }

    public boolean getDescriptionIsFareChanging() {
        return descriptionIsFareChanging;
    }

    public void setDescriptionIsFareChanging(boolean descriptionIsFareChanging) {
        this.descriptionIsFareChanging = descriptionIsFareChanging;
    }

    public double getDescriptionVehicleSpeed() {
        return descriptionVehicleSpeed;
    }

    public void setDescriptionVehicleSpeed(double descriptionVehicleSpeed) {
        this.descriptionVehicleSpeed = descriptionVehicleSpeed;
    }

    @XmlTransient
    public List<RpsRouteTimeSchedule> getRpsRouteTimeScheduleList() {
        return rpsRouteTimeScheduleList;
    }

    public void setRpsRouteTimeScheduleList(List<RpsRouteTimeSchedule> rpsRouteTimeScheduleList) {
        this.rpsRouteTimeScheduleList = rpsRouteTimeScheduleList;
    }

    @XmlTransient
    public List<RpsRouteStations> getRpsRouteStationsList() {
        return rpsRouteStationsList;
    }

    public void setRpsRouteStationsList(List<RpsRouteStations> rpsRouteStationsList) {
        this.rpsRouteStationsList = rpsRouteStationsList;
    }

    public RpsVehicleType getDescriptionVehicleType() {
        return descriptionVehicleType;
    }

    public void setDescriptionVehicleType(RpsVehicleType descriptionVehicleType) {
        this.descriptionVehicleType = descriptionVehicleType;
    }

    public RpsStation getDescriptionFareChangingStation() {
        return descriptionFareChangingStation;
    }

    public void setDescriptionFareChangingStation(RpsStation descriptionFareChangingStation) {
        this.descriptionFareChangingStation = descriptionFareChangingStation;
    }

    public RpsDirectionType getDescriptionDirectionType() {
        return descriptionDirectionType;
    }

    public void setDescriptionDirectionType(RpsDirectionType descriptionDirectionType) {
        this.descriptionDirectionType = descriptionDirectionType;
    }

    @XmlTransient
    public List<RpsRoutePaymentDetail> getRpsRoutePaymentDetailList() {
        return rpsRoutePaymentDetailList;
    }

    public void setRpsRoutePaymentDetailList(List<RpsRoutePaymentDetail> rpsRoutePaymentDetailList) {
        this.rpsRoutePaymentDetailList = rpsRoutePaymentDetailList;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (descriptionId != null ? descriptionId.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof RpsRouteDescription)) {
            return false;
        }
        RpsRouteDescription other = (RpsRouteDescription) object;
        if ((this.descriptionId == null && other.descriptionId != null) || (this.descriptionId != null && !this.descriptionId.equals(other.descriptionId))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.route.system.entity.RpsRouteDescription[ descriptionId=" + descriptionId + " ]";
    }

    public RpsStation getDescriptionEndStation() {
        return descriptionEndStation;
    }

    public void setDescriptionEndStation(RpsStation descriptionEndStation) {
        this.descriptionEndStation = descriptionEndStation;
    }

    public RpsStation getDescriptionStartStation() {
        return descriptionStartStation;
    }

    public void setDescriptionStartStation(RpsStation descriptionStartStation) {
        this.descriptionStartStation = descriptionStartStation;
    }
    public String findCompleteLabel() {
        if((descriptionStartStation != null) && (descriptionEndStation != null) ) {
          return descriptionVehicleName + " " + descriptionStartStation.getStationName() + " - " + descriptionEndStation.getStationName();  
        }
        
        return "";
    }
    
}
